<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function(){
            var parent = document.getElementsByClassName('parent')[0]
            var child = document.getElementsByClassName('child')[0]
            var grand_child = document.getElementsByClassName('grand_child')[0]
            parent.addEventListener('click',function(e){
                // e.stopImmediatePropagation()//阻止事件捕获
                console.log(1)
            })
            child.addEventListener('click',function(e){
                // e.stopPropagation()  //阻止事件冒泡
                console.log(2)
            })
            grand_child.addEventListener('click',function(e){
                // e.stopPropagation()  //阻止事件冒泡
                console.log(3)
            })
            //点击grand_child   3 2 1
        }
    </script>
    <style>
        .parent{
            height: 300px;
            width: 300px;
            border: 1px solid red;
        }
        .child{
            height:200px;
            width: 200px;
            border:1px solid blue;
            margin: 0 auto;
        }
        .grand_child{
            height:100px;
            width: 100px;
            border:1px solid yellow;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div class="parent">
        parent
        <div class="child">
            child
            <div class="grand_child">
                grand_child
            </div>
        </div>
    </div>
</body>
</html>